import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Day01T3
{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        List<Integer>[] listArray = new List[101];

        for(int i = 0 ; i < n ; i ++){
            int cerId , seatId , tryId;
            cerId = sc.nextInt();
            tryId = sc.nextInt();
            seatId = sc.nextInt();
            List<Integer> list = new ArrayList<>();
            list.add(cerId);
            list.add(seatId);
            listArray[tryId] = list;
        }

        int m;
        m = sc.nextInt();
        for(int i = 0 ; i < m ; i ++){
            int tryId = sc.nextInt();
            List<Integer> list = listArray[tryId];

            for(int number : list){
                System.out.println(number + " ");
            }
            System.out.println();
        }
    }
}
